package productknowlege
import org.compass.core.engine.SearchEngineQueryParseException
import org.product.*
import org.knowlege.*
class SearchController {
	def searchableService
	def index = {
		def query = params.q
		def domainName = params.domainName?:"product"
		if (!query) {
			return [:]
		}
		try {
			//def	searchResult = Product.search(query, params)
			//render view:"/product/search",model:[searchResult: searchResult]
			def searchResult ;
			if(domainName=="product"){
				searchResult = Product.search(query, params)
				render view:"/product/search",model:[searchResult: searchResult]
			}else if(domainName=="knowlege"){
				searchResult = Knowlege.search(query, params)
				render view:"/knowlege/search",model:[searchResult: searchResult]
			}else{
				searchResult = searchableService.search(query, params)
				return [searchResult: searchResult]
			}
		}  catch (SearchEngineQueryParseException ex) {
            return [parseException: true]
        }
	}
}
